/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ua.i.kotionokyurievna.jewelryweb.entities;

import java.io.Serializable;
import javax.persistence.*;

/**
 *
 * @author Kateryna_Reznik
 */
@Entity
@Table ( name = "works")
@NamedQueries({
    @NamedQuery ( name = "Works.findById",
        query="SELECT w.workId, w.workTitle, w.price "
        + "FROM Work w "
        + "WHERE w.workId = :workId"),
    @NamedQuery ( name = "Works.findByTitle",
        query="SELECT w.workId, w.workTitle, w.price "
        + "FROM Work w "
        + "WHERE w.workTitle = :workTitle"),
    @NamedQuery ( name = "Works.findByPrice",
        query="SELECT w.workId, w.workTitle, w.price "
        + "FROM Work w "
        + "WHERE w.price <= :workPrice ")
})

public class Work implements Serializable{
    @Id
    @GeneratedValue (strategy = GenerationType.TABLE)
    @Column ( name = "work_id" )
    private int workId;
    @Column (name = "work_title")
    private String workTitle;
    private double price;

    public Work() {
    }

    public Work(String workTitle, double price) {
        this.workTitle = workTitle;
        setPrice(price);
        
    }

    public Work(int workId, String workTitle, double price) {
        this.workId = workId;
        this.workTitle = workTitle;
        if ( price > 0 ){
           this.price = price;
        }
        else{
           this.price = 0.0;
        }
    }
    
    public Work( Work work ){
        if ( work != null ){
            this.workId = work.workId;
            this.workTitle = work.workTitle;
            if ( price > 0 ){
                this.price = work.price;
            }
            else{
                this.price = 0.0;
            }
        }
    }

    public int getWorkId() {
        return workId;
    }

    public String getWorkTitle() {
        return workTitle;
    }

    public void setWorkTitle(String workTitle) {
        this.workTitle = workTitle;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        if ( price > 0 ){
            this.price = price;
        }
        else{
            this.price = 0.0;
        }
    }

    @Override
    public String toString() {
        return "Work{" + "workId=" + workId + ", workTitle=" + 
                workTitle + ", price=" + price + '}';
    }

    @Override
    public int hashCode() {
        int hash = 3;
        hash = 89 * hash + (this.workTitle != null ? this.workTitle.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Work other = (Work) obj;
        if ((this.workTitle == null) ? (other.workTitle != null) : !this.workTitle.equals(other.workTitle)) {
            return false;
        }
        return true;
    }
    
}
